package View
{
	import laya.display.Sprite;
	import laya.utils.Handler;
	
	/**
	 * 类描述
	 * @author sixsir
	 * @date 2016-11-20下午4:23:39
	 */
	public class Background extends Sprite
	{
		public function Background()
		{
			super();
			init();
		}
		
		private function init():void
		{
			//创建一个容器
			this.box = new Laya.Sprite();
			this.addChild(box);
			
			Laya.loader.load("res/background.png", Handler.create(this, onComplete));
		}
		
		private function onComplete():void
		{
			bg1 = new Sprite();
			bg1.loadImage("res/background.png");
			box.addChild(bg1);
			
			bg2 = new Sprite();
			bg2.loadImage("res/background.png");
			bg2.pos(0, -STAGE_HEIGHT);
			box.addChild(bg2);
			
			Laya.timer.frameLoop(1, this, onLoop);
		}
		
		//地图不断移动
		private function onLoop():void
		{
			bg1.y++;
			bg2.y++;
			
			if(bg1.y > STAGE_HEIGHT)
			{
				bg1.y = -STAGE_HEIGHT+2;
			}
			
			if(bg2.y > STAGE_HEIGHT)
			{
				bg2.y = -STAGE_HEIGHT+2;
			}
		}
		
		private const STAGE_HEIGHT:int = 852;
		private var box:Sprite;
		private var bg1:Sprite;
		private var bg2:Sprite;
	}
}